import 'package:flutter/material.dart';
import 'package:waterfall_flow/waterfall_flow.dart';

import '../../short_video/api/short_video_api.dart';
import '../../short_video/models/short_video_list_model.dart';
import '../widgets/project_page_cell.dart';

class ProjectPage extends StatefulWidget {
  const ProjectPage({super.key});

  @override
  State<ProjectPage> createState() => _ProjectPageState();
}

class _ProjectPageState extends State<ProjectPage> {
  List<ShortVideoListItemModel>? videoList;

  @override
  void initState() {
    super.initState();

    // 获取视频列表接口
    ShortVideoApi.getVideoListData().then((result) {
      setState(() {
        videoList = result;
      });
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("相册")),
      body: WaterfallFlow.builder(
        padding: EdgeInsets.all(6),
        gridDelegate: SliverWaterfallFlowDelegateWithFixedCrossAxisCount(
          crossAxisCount: 2,
          mainAxisSpacing: 6,
          crossAxisSpacing: 6,
        ),
        itemBuilder: (ctx, index) {
          return ProjectPageCell(itemModel: videoList![index]);
        },
        itemCount: videoList?.length ?? 0,
      ),
    );
  }
}
